import { Injector } from '@angular/core';
import { Router } from '@angular/router';
import { Token } from '../model/token';
import { AuthConfig } from '../../config/auth.config';

export function check(model: Token): boolean {
  return (
    model != null && typeof model.token === 'string' && model.token.length > 0
  );
}

export function toLogin(options: AuthConfig, injector: Injector): void {
  if (options.token_invalid_redirect) {
    setTimeout(() => {
      injector.get(Router).navigate([options.login_url]);
    });
  }
}
